﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RBOSS.Data;
using RBOSS.Business.CustomerModule;

namespace RBOSS.Business.InternalUser
{
    public class Productapproval
    {
        public int ProductId { get; set; }
        public int UserId { get; set; }
        public int CategoryId { get; set; }
        public string ProductName { get; set; }
        public decimal UnitPrice { get; set; }
        public string Image { get; set; }
        public int Quantity { get; set; }
        public string Description { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public bool IsProductActive { get; set; }
        public bool IsProductEnabled { get; set; }

        RBOSSEntities rb = new RBOSSEntities();
        public List<Productapproval> getallproducts()
        {
            List<Productapproval> lstproudect = new List<Productapproval>();
       
            var query = from pro in rb.Products
                        join us in rb.Users
                        on pro.UserId equals us.UserId
                        select new Productapproval {ProductId=pro.ProductId,UserId=pro.UserId
                            ,ProductName=pro.ProductName,
                            UnitPrice=pro.UnitPrice,Image=pro.Image
                        ,Quantity=pro.Quantity,
                        Description=pro.Description,
                        FirstName=us.FirstName,
                        LastName=us.LastName,
                        IsProductEnabled=pro.IsProductEnabled,
                        IsProductActive=pro.IsProductActive,
                        Email=us.Email,};

            foreach (Productapproval item in query)
            {
                lstproudect.Add(item);
                
            }

            return lstproudect;

        }
        public List<Productapproval> getproducts()
        {
            List<Productapproval> lstproudect = new List<Productapproval>();

            var query = from pro in rb.Products
                        join us in rb.Users
                        on pro.UserId equals us.UserId
                        where pro.IsProductEnabled==false
                        select new Productapproval
                        {
                            ProductId = pro.ProductId,
                            UserId = pro.UserId
                            ,
                            ProductName = pro.ProductName,
                            UnitPrice = pro.UnitPrice,
                            Image = pro.Image,
                            IsProductEnabled = pro.IsProductEnabled,
                            IsProductActive = pro.IsProductActive,
                            Quantity = pro.Quantity,
                            Description = pro.Description,
                            FirstName = us.FirstName,
                            LastName = us.LastName,
                            Email = us.Email,
                        };

            foreach (Productapproval item in query)
            {
                lstproudect.Add(item);

            }

            return query.ToList();

        }

        public void updateIsProductEnabled(int productid,bool IsEnabled)
        {
            var query = rb.Products.Where(e => e.ProductId == productid).FirstOrDefault();
            query.IsProductEnabled = IsEnabled;
            rb.SaveChanges();
        }
    }
}
